package com.atguigu.controller;

import java.io.*;

import com.atguigu.pojo.Company;
import com.atguigu.service.CompanyService;
import com.atguigu.service.impl.CompanyServiceImpl;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/delivery/toadd")
public class DeliveryToAddController extends HttpServlet {
    private CompanyService companyService = new CompanyServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            try {
                List<Company> companyList = companyService.findAllCompany();
                request.setAttribute("companyList", companyList);
                request.getRequestDispatcher("/add.jsp").forward(request, response);
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}